<?php

namespace IDock\Insurance\CHAC\Request;

use IDock\Http\RequestFormat;
use IDock\IDock\IDockEnums;
use IDock\Insurance\CHAC\CHACEnums;
use IDock\Insurance\CHAC\Response\FUploadFileResponse;
use IDock\Visitor\UploadFileVisitor;

class FUploadFileRequest extends AllCHACRequest
{
    protected $route = 'new/wechat/uploadImage';

    protected $response = FUploadFileResponse::class;

    protected $urlTip = '影像上传';

    protected $inLog = true;

    protected $format = RequestFormat::FORM;

    public $file;

    public $requestData = [];

    /*** @var  UploadFileVisitor $visitor */
    protected $visitor;

    public function init()
    {
        $this->requestData = [
            'partnerCode' => $this->visitor->argc['partnerCode'] ?? '',
            'user' => $this->visitor->argc['userName'] ?? '',
            'passWord' => $this->visitor->argc['passWord'] ?? '',
            'bussNo' => $this->visitor->inquiryNo,
            'bussType' => 'T',
        ];
    }

    public function generate(): array
    {
        $extArr = explode('.',basename($this->file['url']));
        $ext = end($extArr);

        $typePath = CHACEnums::$uploadFileType[$this->file['type'] .'-'.(int)$this->visitor->argc['isNewVehicle']];
        $typeName = CHACEnums::$typePathName[$typePath];

        $this->requestData['typePath'] = $typePath;
        $this->requestData['typeName'] = $typeName;
        $this->requestData['fileOrgName'] = IDockEnums::$uploadFileType[$this->file['type']].rand(1000,9999).'.'.$ext;
        $this->requestData['fileContent'] = $this->file['base64'];

        return $this->requestData;
    }

}
